﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace proyGestionVisitas.Gestion
{
    public partial class MostrarAcuerdo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["usu"] == null) { Response.Redirect("~/Account/Login.aspx"); return; }
            if (!IsPostBack)
            {
                if (Request.QueryString["arch"] == null || Request.QueryString["arch"].ToString() == String.Empty) { Salir(); return; }
                String filename = Request.QueryString["arch"].ToString();
                String rutaFisica = Server.MapPath("UploadFiles\\" + filename);
                if (!(System.IO.File.Exists(rutaFisica))) { ArchivoNoExiste(); Salir(); return; }
                String ruta = Path.Combine("~/Gestion/UploadFiles/", filename);
                Response.Clear();
                Response.ContentType = "Application/pdf";
                Response.TransmitFile(ruta);
                Response.Flush();
                Response.End();
            }
        }

        private void Salir()
        {
            String script = "window.self.close();";
            Page page = (Page)Context.Handler;
            ScriptManager.RegisterStartupScript(page, page.GetType(), "cerrar", script, true);
        }

        private void ArchivoNoExiste()
        {
            String script = "alert('Archivo No Existe.');";
            Page page = (Page)Context.Handler;
            ScriptManager.RegisterStartupScript(page, page.GetType(), "showalert", script, true);
        }

    }
}